@extends('admin::public.base')
@section('content')
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <header class="title">添加图标</header>
        </div>
        <div class="layui-card-body">
            <div class="layui-form">
                <div class="layui-form-item">
                    <label for="" class="layui-form-label layui-required">图标样式</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" id="name" autocomplete="off" value="" class="layui-input" placeholder="如：fa-user">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="" class="layui-form-label layui-required">图标名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="desc" id="desc" autocomplete="off" value="" class="layui-input" placeholder="如：用户,人员">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn" lay-submit=""  lay-filter="submit">确 认</button>
                        <a href="javascript:history.back(-1)" class="layui-btn layui-btn-primary" >返 回</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script>
        layui.use(['layer','form'],function () {
            var layer = layui.layer;
            var form = layui.form;
            //表单提交
            form.on('submit(submit)', function (data) {
                //验证表单
                if (!data.field.name) {
                    layer.tips('请输入图标样式', '#name', { tips: 3 });
                    return false;
                }
                if (!data.field.desc) {
                    layer.tips('请输入图标名称', '#desc', { tips: 3 });
                    return false;
                }
                //ajax提交
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: "{{route('admin.icon.store')}}",
                    data: data.field,
                    success: function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg, {
                                time: 2000
                            }, function () {
                                location.href = "{{route('admin.icon')}}";
                            })
                        } else {
                            layer.msg(data.msg);
                        }
                    },
                    error: function (data) {
                        layer.msg("服务器开小差啦");
                    }
                });
            })
        })
    </script>
@endsection
